<%@page import="qldc.pm.qtht.dmdc.service.DanTocLocalServiceUtil"%>
<%@page import="qldc.pm.qtht.dmdc.model.DanToc"%>
<%@page import="qldc.pm.qlktcsdldc.service.DanhMucSoBanNganhLocalServiceUtil"%>
<%@page import="qldc.pm.qlktcsdldc.model.DanhMucSoBanNganh"%>
<%@page import="qldc.pm.qtht.dmdc.service.TinhLocalServiceUtil"%>
<%@page import="qldc.pm.qtht.dmdc.model.Tinh"%>
<%@page import="com.liferay.portal.kernel.util.Constants"%>
<%@page import="qldc.pm.qlktcsdldc.actions.ActionHandlerConstant"%>
<%@ include file="../init.jsp"%>

<%

	String redirect = ParamUtil.getString(request, "redirect");
	
	PortletURL backURL = renderResponse.createRenderURL();
	backURL.setParameter("mvcPath", "/html/qlktcsdldc/quan_ly_tai_khoan.jsp");
	backURL.setParameter("tabs1", QLKTCSDLDCContants.PAGEID_QLTK_MAN_HINH_CHINH);
	backURL.setParameter("redirect", redirect);
	
	List<Tinh> tinhs = TinhLocalServiceUtil.findAll();
	List<DanhMucSoBanNganh> danhMucSoBanNganhs = DanhMucSoBanNganhLocalServiceUtil.searchAll();
	List<DanToc> danTocs = DanTocLocalServiceUtil.findAll();
%>

<portlet:actionURL var="addNguoiDungURL">
	<portlet:param name="<%=ActionHandlerConstant.ACTION_HANDLER_PARAM%>" value="<%=ActionHandlerConstant.QUAN_LY_TAI_KHOAN_ACTION%>" />
	<portlet:param name="<%=Constants.ACTION%>" value="addNguoiDung" />
	<portlet:param name="redirect" value="<%=backURL.toString() %>" />
</portlet:actionURL>

<portlet:resourceURL var="loadQuanHuyen" id="loadQuanHuyen">
	<portlet:param name="tinhIdSelected" value="{0}" />
</portlet:resourceURL>

<portlet:resourceURL var="loadPhuongXa" id="loadPhuongXa">
	<portlet:param name="quanHuyenIdSelected" value="{0}" />
</portlet:resourceURL>

<h2 class="tle-Content">
	<liferay-ui:message key="them-moi-tai-khoan" />
</h2>
<div id="<portlet:namespace/>them-moi-tai-khoan-content">
	<form  method="POST" action="" onsubmit="return false;" name="<portlet:namespace/>fmThemMoiNguoiDung" id="<portlet:namespace/>fmThemMoiNguoiDung">
		<%
			long tinhId = ParamUtil.getLong(request, "tinh");
			long quanHuyenId = ParamUtil.getLong(request, "quanHuyen");
			long phuongXaId = ParamUtil.getLong(request, "phuongXa");
		%>
		<table class="gridnormal">
			<tr>
				<td>
					<liferay-ui:message key="so-ban-nganh" />
				</td>
				<td>
					<select class="" readonly="readonly"   id="<portlet:namespace/>soBanNganh"  name="<portlet:namespace/>soBanNganh">
						<option value="0"><liferay-ui:message key="chon-so-ban-nganh" /></option>
						<%
							for (DanhMucSoBanNganh danhMucSoBanNganh : danhMucSoBanNganhs) {
						%>
						<option value="<%=danhMucSoBanNganh.getIDQLKT_DanhMucSoBanNganh()%>"><%=danhMucSoBanNganh.getTenSoBanNganh()%></option>
						<%
							}
						%>
					</select>
				</td>
				<td  colspan="2"/>
			</tr>
	
			<tr>
				<td>
					<liferay-ui:message key="ten-dang-nhap" />
				</td>
				<td>
					<input type="text" name="<portlet:namespace/>tenDangNhap" id="<portlet:namespace/>tenDangNhap" />
				</td>
				<td  colspan="2"/>
			</tr>
			
			<tr>
				<td>
					<liferay-ui:message key="ho-ten" />
				</td>
				<td>
					<input type="text"  name="<portlet:namespace/>hoTen" id="<portlet:namespace/>hoTen" />
				</td>
				<td  colspan="2"/>
			</tr>
	
			<tr>
				<td>
					<liferay-ui:message key="so-cmnd" />
				</td>
				<td>
					<input type="text" name="<portlet:namespace/>soCMND" id="<portlet:namespace/>soCMND" value="" />
				</td>
				<td  colspan="2"/>
			</tr>
	
			<tr>
				<td>
					<liferay-ui:message key="gioi-tinh" />
				</td>
				<td>
					<select class=""  id="<portlet:namespace/>gioiTinh"  name="<portlet:namespace/>gioiTinh">
						<option value="0"><liferay-ui:message key="nu" /></option>
						<option value="1"><liferay-ui:message key="nam" /></option>
					</select>
				</td>
				<td  colspan="2"/>
			</tr>
	
			<tr>
				<td>
					<liferay-ui:message key="dan-toc" />
				</td>
				<td>
					<select class=""  id="<portlet:namespace/>danToc"  name="<portlet:namespace/>dan-toc">
						<option value="0"><liferay-ui:message key="chon-dan-toc" /></option>
						<%
							for (DanToc danToc : danTocs) {
						%>
						<option value="<%=danToc.getDanTocId()%>"><%=danToc.getTenDanToc()%></option>
						<%
							}
						%>
					</select>
				</td>
				<td  colspan="2"/>
			</tr>
			<tr>
				<td>
					<liferay-ui:message key="dc-thuong-tru" />
				</td>
				<td colspan="3">
					<select class=""  id="<portlet:namespace/>tinh"  name="<portlet:namespace/>tinh" 
					onchange="loadNewQuanHuyen('<portlet:namespace />','<%=loadQuanHuyen.toString()%>',<%=quanHuyenId%>,'tinh','quanHuyen', 'phuongXa');">
						<option value="0"><liferay-ui:message key="chon-tinh" /></option>
						<%
							for (Tinh tinh : tinhs) {
						%>
						<option value="<%=tinh.getTinhId()%>"
							<%=tinh.isLaMacDinh() ? "selected=selected" : ""%>><%=tinh.getTenTinh()%></option>
						<%
							}
						%>
					</select>
					<select class=""  id="<portlet:namespace/>quanHuyen"  name="<portlet:namespace/>quanHuyen" 
						onchange="loadNewPhuongXa('<portlet:namespace />','<%=loadPhuongXa.toString()%>',<%=phuongXaId%>,'tinh','quanHuyen', 'phuongXa');">
						<option value="0"><liferay-ui:message key="chon-quan-huyen" /></option>
					</select>
					<select class=""  id="<portlet:namespace/>phuongXa"  name="<portlet:namespace/>phuongXa">
						<option value="0"><liferay-ui:message key="chon-phuong-xa" /></option>
					</select>
					<input type="text" name="<portlet:namespace/>diaChi" 
							id="<portlet:namespace/>diaChi" value="" />
				</td>
			</tr>
			<tr>
				<td>
					<liferay-ui:message key="giai-thich" />
				</td>
				<td colspan="3">
					<textarea rows="5" cols="150" name="<portlet:namespace/>giaiThich" 
							id="<portlet:namespace/>giaiThich">
					</textarea>
				</td>
			</tr>
			<tr>
				<td colspan="3">
					<input type="submit" class="" onclick="addNguoiDung()" value="<liferay-ui:message key="luu" />" id="<portlet:namespace/>luu" /> 
					<input type="submit" class="" onclick="thoataddNguoiDung()" value="<liferay-ui:message key="thoat" />"  id="<portlet:namespace/>thaoTac" />
				</td>			
			</tr>
		</table>
	</form>
</div>

<script  type="text/javascript">
$(document).ready(function() {	
	loadNewQuanHuyen('<portlet:namespace />','<%=loadQuanHuyen.toString()%>',<%=quanHuyenId%>,'tinh','quanHuyen', 'phuongXa');
	loadNewPhuongXa('<portlet:namespace />','<%=loadPhuongXa.toString()%>',<%=phuongXaId%>,'tinh','quanHuyen', 'phuongXa');
});

function validationFromAddNguoiDung(){
	var soBanNganh = $("#<portlet:namespace/>soBanNganh");
	if(!soBanNganh || $.trim(soBanNganh.val()) == "" || $.trim(soBanNganh.val()) == "0"){
		showPopupConfirm('<liferay-ui:message key="xin-vui-long-nhap-thong-tin" />  : [<liferay-ui:message key="so-ban-nganh" />]',['Ok'],function(index){
			soBanNganh.focus();				
		});
		return false;
	}
	var tenDangNhap = $("#<portlet:namespace/>tenDangNhap");
	if(!tenDangNhap || $.trim(tenDangNhap.val()) == ""){
		showPopupConfirm('<liferay-ui:message key="xin-vui-long-nhap-thong-tin" />  : [<liferay-ui:message key="ten-danh-nhap" />]',['Ok'],function(index){
			tenDangNhap.focus();				
		});
		return false;
	}
	
	var hoTen = $("#<portlet:namespace/>hoTen");
	if(!hoTen || $.trim(hoTen.val()) == ""){
		showPopupConfirm('<liferay-ui:message key="xin-vui-long-nhap-thong-tin" />  : [<liferay-ui:message key="ho-va-ten" />]',['Ok'],function(index){
			hoTen.focus();				
		});
		return false;
	}
	
	var soCMND = $("#<portlet:namespace/>soCMND");
	if(!soCMND || $.trim(soCMND.val()) == ""){
		showPopupConfirm('<liferay-ui:message key="xin-vui-long-nhap-thong-tin" />  : [<liferay-ui:message key="so-cmnd" />]',['Ok'],function(index){
			soCMND.focus();				
		});
		return false;
	}
	var danToc = $("#<portlet:namespace/>danToc");
	if(!danToc || $.trim(danToc.val()) == "" || $.trim(danToc.val()) == "0"){
		showPopupConfirm('<liferay-ui:message key="xin-vui-long-nhap-thong-tin" />  : [<liferay-ui:message key="dan-toc" />]',['Ok'],function(index){
			danToc.focus();				
		});
		return false;
	}
	var tinh = $("#<portlet:namespace/>tinh");
	if(!tinh || $.trim(tinh.val()) == "" || $.trim(tinh.val()) == "0"){
		showPopupConfirm('<liferay-ui:message key="xin-vui-long-nhap-thong-tin" />  : [<liferay-ui:message key="tinh" />]',['Ok'],function(index){
			tinh.focus();				
		});
		return false;
	}
	
	var quanHuyen = $("#<portlet:namespace/>quanHuyen");
	if(!quanHuyen || $.trim(quanHuyen.val()) == "" || $.trim(quanHuyen.val()) == "0"){
		showPopupConfirm('<liferay-ui:message key="xin-vui-long-nhap-thong-tin" />  : [<liferay-ui:message key="quan-huyen" />]',['Ok'],function(index){
			quanHuyen.focus();				
		});
		return false;
	}
	var phuongXa = $("#<portlet:namespace/>phuongXa");
	if(!phuongXa || $.trim(phuongXa.val()) == "" || $.trim(phuongXa.val()) == "0"){
		showPopupConfirm('<liferay-ui:message key="xin-vui-long-nhap-thong-tin" />  : [<liferay-ui:message key="phuong-xa" />]',['Ok'],function(index){
			phuongXa.focus();				
		});
		return false;
	}
	
	var diaChi = $("#<portlet:namespace/>diaChi");
	if(!diaChi || $.trim(diaChi.val()) == ""){
		showPopupConfirm('<liferay-ui:message key="xin-vui-long-nhap-thong-tin" />  : [<liferay-ui:message key="dia-chi" />]',['Ok'],function(index){
			diaChi.focus();				
		});
		return false;
	}
	return true;
};

function addNguoiDung(){
	if(validationFromAddNguoiDung()){
		showPopupConfirm('<liferay-ui:message key="ban-co-muon-luu-thong-tin" />',['Yes','No'],function(index){
			if (index == 0){
				var url = '<%=addNguoiDungURL.toString()%>';
				$("#<portlet:namespace/>fmThemMoiNguoiDung").attr('action', url);
				$("#<portlet:namespace/>fmThemMoiNguoiDung").attr('onsubmit', 'return true;');
				$("#<portlet:namespace/>fmThemMoiNguoiDung").submit();
			}
		});	
	}
};
function thoataddNguoiDung(){
	location.href = '<%=backURL.toString()%>';
}
</script>